package com.common.utils.wxpay;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class MyConfig extends WXPayConfig {

	private byte[] certData;
	
	private String _appID;
	
	private String _mchID;
	
	private String _key;
	
	

	

	

	public String get_appID() {
		return _appID;
	}

	public void set_appID(String _appID) {
		this._appID = _appID;
	}

	public String get_mchID() {
		return _mchID;
	}

	public void set_mchID(String _mchID) {
		this._mchID = _mchID;
	}

	public String get_key() {
		return _key;
	}

	public void set_key(String _key) {
		this._key = _key;
	}

	@Override
	String getAppID() {
		return get_appID();//"你的appid";
	}

	@Override
	String getMchID() {
		return get_mchID();//"你的商户id";
	}

	@Override
	String getKey() {
		return get_key();//"你的商户api安全key，在商户平台api安全目录下可设置";
	}
   public MyConfig() throws Exception {
//	        String certPath = "classpath:apiclient_cert.p12";
//	        File file = new File(certPath);
//	        InputStream certStream = new FileInputStream(file);
//	        this.certData = new byte[(int) file.length()];
//	        certStream.read(this.certData);
//	        certStream.close();
	        
	        ClassPathResource classPathResource = new ClassPathResource("apiclient_cert.p12");
            //获取文件流
            InputStream certStream = classPathResource.getInputStream();
            this.certData = IOUtils.toByteArray(certStream);
            certStream.read(this.certData);
            certStream.close();
    }
	@Override
	InputStream getCertStream() {
		ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
	}

	@Override
    IWXPayDomain getWXPayDomain() {
		return new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {
            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo("api.mch.weixin.qq.com", false);
            }
        };
	}
	@Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }

}
